<script src="<?= $url_styles ?>js/plugins/formselements/jquery.maskedinput-1.3.min.js"></script>
<script src="<?= $url_styles ?>js/plugins/formselements/ui.spinner.min.js"></script>
<script src="<?= $url_styles ?>js/plugins/gallery/jquery.colorbox-min.js"></script>
<script>
	$('.form-horizontal [name="start"]').datepicker();
	$('.form-horizontal [name="end"]').datepicker();
	$('.form-horizontal [name="start"]').datepicker('option','dateFormat','dd/mm/yy');
	$('.form-horizontal [name="end"]').datepicker('option','dateFormat','dd/mm/yy');
    var image_index=0;
	$('#add_image').live('click',function(){
        image_index++;
		$('#images').append('<div><input type="file" name="images_'+image_index+'" class="input-xlarges"/>\n\
							<a href="javascript:;" class="delete_image"><?= lang('delete') ?></a></div>');
		return false;
	});
	$('.delete_image').live('click',function(){
		$(this).parent().fadeOut('fast',function(){$(this).remove()});
	});
	$('#tab4_check').click(function(){
		$('.form-horizontal [name="catalogues[]"]').attr('checked',this.checked);
	})
	$('#tab5_check').click(function(){
        $('.form-horizontal [name="locations[]"]').attr('checked',this.checked);
	})
    $('#tab4_check').click(function(){
        $('.form-horizontal [name="catalogues[]"]').attr('checked',this.checked);
    })
    $('#tab5_check').click(function(){
        $('.form-horizontal [name="locations[]"]').attr('checked',this.checked);
    })
	$(document).ready(function(){
		$('.form-horizontal').formParse({
			data: <?= json_encode($product) ?>,
			errors: <?= json_encode($errors) ?>,
			specialFields: ['info','locations','catalogues','images'],
			exceptFields: ['images'],
			ajax: true
		});
		 
        $('#selectfile').uploadInit({
			url: '<?= url_create('admin', 'file', 'upload') ?>',
			multi_selection: false,
			imageContainer: $('#albumImage'),
			imageVar: 'image_id'
		})
		
		$('#selectfiles').uploadInit({
			url: '<?= url_create('admin', 'file', 'upload') ?>',
			multi_selection: true,
			imageContainer: $('#basicGallery'),
			imageVar: 'images[]'
		})
	
		$(".delete").click(function(){
			$(this).parents("li").fadeOut().remove();
		});
		

        /* --->> 1 - Basic gallery options show/hide --------------*/
        $("#basicGallery > li").hoverIntent(
		function () {
			$(this).find("div").fadeIn("fast");
		},
		function () {
			$(this).find("div").fadeOut("fast");
		}
	);
		//<![CDATA[
        $(window).load(function(){
//			var position;
//			var parentpos;
			$("#basicGallery li").mousedown(function(){
//                position = $(this).index();
//                parentpos =  $(this).parent().index();
				$("#basicGallery").sortable({
					items: "> li",
					revert: true
				}).disableSelection();
			});
//			$("td").mouseup(function(){
//                $("div").html(position);
//			});
               
        });//]]>  
    });
</script>
